<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改商品</title>
    <th:block th:include="~{common/common::commonHead}"/>

</head>
<body data-width="850" data-height="420">
<form data-auto-set-value="edit" class="form-horizontal" data-get-url="invoice/getInvoiceDetail" role="form" th:action="@{/invoice/editInvoiceDetail}">
    <input type="hidden" id="goodsId" name="id">
    <input type="hidden" id="goodsImg" name="goodsImg">
    <div class="col-xs-4">
        <div id="localImg" style="margin-left: 45px;">
            <img id="preview" th:src="@{/img/type/defaultGoodsImg.png}" width="300" height="300" style="display: block; width: 300px; height: 300px; margin: auto">
        </div>
        <div class="iconic-input right">
            <button type="button" class="btn btn-default" style="pointer-events: none; margin-left: 160px; margin-top: 3px;">
                点击上传
            </button>
            <input type="file" name="file" id="doc" style="width:78px;height: 32px; opacity: 0; position: relative; margin-top: -30px; margin-left: 160px;" onchange="setImagePreview();">
        </div>
    </div>
    <div class="col-xs-8">
        <div class="form-group">
            <label class="col-lg-2 col-md-2 col-sm-4 col-xs-4 control-label"> 商品名称 </label>
            <div class="col-lg-6 col-md-4 col-sm-8 col-xs-8">
                <div class="iconic-input right">
                    <input id="goodsName" name="goodsName" type="text" class="form-control spinner" placeholder="1~20位字符" disabled required maxlength="20">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-8">
        <div class="form-group">
            <label class="col-lg-2 col-md-2 col-sm-4 col-xs-4 control-label"> 商品数量 </label>
            <div class="col-lg-6 col-md-4 col-sm-8 col-xs-8">
                <div class="iconic-input right">
                    <input id="goodsCount" name="count" type="number" class="form-control spinner" placeholder="结算价格"
                           required data-valid-decimal="true" min="0.01" max="10000">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-8">
        <div class="form-group">
            <label class="col-lg-2 col-md-2 col-sm-4 col-xs-4 control-label"> 商品结算价 </label>
            <div class="col-lg-6 col-md-4 col-sm-8 col-xs-8">
                <div class="iconic-input right">
                    <input id="goodsSettlementPrice" name="goodsSettlementPrice" type="number" class="form-control spinner" placeholder="结算价格"
                           disabled  required data-valid-decimal="true" data-decimal="true" min="0.01" max="10000">
                </div>
            </div>
        </div>
    </div>
    <!--<div class="col-xs-8">-->
        <!--<div class="form-group">-->
            <!--<label class="col-lg-2 col-md-2 col-sm-4 col-xs-4 control-label"> 商品单位 </label>-->
            <!--<div class="col-lg-6 col-md-4 col-sm-8 col-xs-8">-->
                <!--<div class="iconic-input right">-->
                    <!--<input id="goodsUnit" name="goodsUnit" type="text" class="form-control spinner" placeholder="1~5位字符"-->
                           <!--disabled required maxlength="5">-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->
    <!--<div class="col-xs-8">-->
        <!--<div class="form-group">-->
            <!--<label class="col-lg-2 col-md-2 col-sm-4 col-xs-4 control-label"> 商品类型 </label>-->
            <!--<div class="col-lg-6 col-md-4 col-sm-8 col-xs-8">-->
                <!--<div class="iconic-input right">-->
                    <!--<select name="goodsType" class="form-control" data-url="goods/listGoodsType" data-value-field="id" data-text-field="typeName"></select>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->

</form>
</body>
</html>
<script>
    //下面用于图片上传预览功能
    function setImagePreview() {
        var docObj=document.getElementById("doc");
        var formData = new FormData();
        formData.append("files", docObj.files[0]);
        $.ajax({
            url: "file/upload",
            type: "POST",
            data: formData,
            processData : false,// 告诉jQuery不要去处理发送的数据
            contentType : false,// 告诉jQuery不要去设置Content-Type请求头
            beforeSend:function(){
                console.log("正在进行，请稍候");
            },
            success : function(data) {
                if (data.code !== '0') {
                    $.error(data.msg);
                } else {
                    console.log(data);
                    var url = data.data[0].url;
                    $("#goodsImg").val(url);
                    $("#preview").attr("src", url);
                }
            },
            error : function() {
                $.error("上传失败");
            }
        });
    }
    function afterAutoSetValue(data) {
        $("#preview").attr("src", data.img);
    }
</script>
